home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 10 - 1994 / 10.08 Aug 94 / Code resource (C++) < prev    next >
Encoding:
Text File  |  1994-07-18  |  649 b   |  22 lines  |  [TEXT/MPS ]

  1. 8) How do I call a code resource from my C++ program?
  2.  
  3. Here's a small program (in C++) which calls a code resource.  For this example the code resource takes 2 arguments, an int and a character pointer.  It assumes that the resource has been merged into the project's .rsrc with type CODE and name myCodeResource.
  4.  
  5. /* UsesCodeResource.cpp */
  6. #include <stdio.h>
  7.  
  8. extern "C" typedef void (*CRPtr) (int, char*);
  9.  
  10. void main()
  11. {
  12.     char myString[20];
  13.     Handle myCRhandle;
  14.  
  15.     myCRhandle = GetNamedResource('CODE',"\pmyCodeResource");
  16.     HLock(myCRhandle);
  17.     (* (CRPtr) (*myCRhandle)) (5,myString);
  18.     HUnlock(myCRhandle);
  19.     printf("myString=\"%s\"\n",myString);
  20. }
  21.  
  22.